/*
    OGLSL Implementation: Per Fragment Lighting
                          uses 1st OpenGL light source

    (c) 2004 by Martin Christen. All Rights Reserved.
*/

varying vec3 Nv;
varying vec3 P;

void main (void)
{ 
  vec3 N = normalize(Nv);
  vec3 E = normalize(-P);

  gl_FragColor = gl_FrontLightModelProduct.sceneColor;

  
  //for (int i=0;i<7;i++)
  int i=0;
  { 
   vec3 L = normalize(gl_LightSource[i].position.xyz-P);
   vec3 R = normalize(-reflect(L,N));

   vec4 Iamb = gl_FrontLightProduct[i].ambient; 
   vec4 Idiff = gl_FrontLightProduct[i].diffuse * max(dot(N,L), 0.0);
   vec4 Ispec = gl_FrontLightProduct[i].specular * pow(max(dot(R,E),0.0),0.3 * gl_FrontMaterial.shininess);

   gl_FragColor +=  (Iamb + Idiff + Ispec);
  }

}
